﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HandLab.LocalApp.Learn.Linq
{
    public class HiLinq
    {
        string[] names = { "Tom","DellMM", "Dick", "David", "Harry", "Mack", "Jerry" };
        List<int> list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        public void TestGo()
        {
            Console.WriteLine("1.(Enumerable.Where)...");
            IEnumerable<string> filteredNames = Enumerable.Where(names, n => n.Length >= 5);
            foreach (string s in filteredNames)
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("2.(names.Where)...");
            IEnumerable<string> filterNames = names.Where(n => n.Length > 4);
            foreach (string s in filterNames)
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("3.(var)...");
            var filterNames2 = names.Where(n => n.Length > 4);
            foreach (string s in filterNames2)
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("4.(查询表达式语法)...");
            var filterNames3 = from n in names
                               where n.Length > 4
                               select n;
            foreach (string s in filterNames3)
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("5.(匿名方法)...");
            var filterNames4 = list.FindAll(
                delegate(int i)
                {
                    return (i % 2) == 0;
                }
                );
            foreach (var num in filterNames4)
                Console.WriteLine("{0}\t", num);

            Console.WriteLine("6.(lamdba)...");
            var filterNames5 = list.FindAll(i => i % 2 == 0);
            foreach (var num in filterNames5)
                Console.WriteLine("{0}\t", num);

            Console.WriteLine("7.(链接查询)...");
            var filterNames6 = names
                .Where(n => n.Contains("D"))
                .OrderBy(n => n.Length)
                .Select(n => n.ToUpper());
            foreach (var num in filterNames6)
                Console.WriteLine(num);

            Console.WriteLine("8.().....");
            //var filterNames7
        }
    }
}
